
$(function(){
 var language_type = localStorage.getItem("language_type");
 if (!language_type) {
  language_type = 1; // 判断本地是否保存语言, 如果没有, 默认中文 1-中文 2-英文
  $(".language_ch1").addClass("language_active")
  localStorage.setItem("language_type", language_type);
 } else if (language_type == 2) { // 如果本地保存的是英文
  $(".language_ch2").addClass("language_active")
  $(".language_ch1").removeClass("language_active")
 } else if (language_type == 1) { // 如果本地保存的是中文
  $(".language_ch1").addClass("language_active")
  $(".language_ch2").removeClass("language_active")
 }
 
 $(".language_ch").click(function () { // 点击切换本中英文, 修改页面的中英文, 保存本地
  $(this).addClass("language_active");
  $(this).siblings().removeClass("language_active")
  if ($(this).html() == '中文') {
   language_type = 1;
   var chObj = $('[data-ch]');
   chObj.each(function () {
    $(this).html($(this).attr("data-ch"))
    $(this).attr("placeholder", $(this).attr("data-ch"))
   })
  } else {
   language_type = 2;
   var enObj = $('[data-en]');
   enObj.each(function () {
    $(this).html($(this).attr("data-en"))
    $(this).attr("placeholder", $(this).attr("data-en"))
   })
  }
  localStorage.setItem("language_type", language_type);
 })


 $(".login_btn1").click(function(){
  let language_type = localStorage.getItem("language_type");
  if (!$('.userName').val()){
   layer.open({
    content: language_type == 1 ? '请填写您的账号名称' : 'Please fill in your account name',
    time: 1
   });
  } else if (!$('.userPass').val()){
   layer.open({
    content: language_type == 1 ? '请输入密码' : 'Please enter the password',
    time: 1
   });
  } else {
   let data1 = {
    m_account: $('.userName').val(),
    m_login_pwd: $(".userPass").val(),
    language_type: language_type
   }
   $.ajax({
    type: 'post',
    url: baseURL + '/index.php?m=login&c=login',
    data: data1,
    success: function success(data) {
     data = JSON.parse(data);
     if (data.code == 1) {
      layer.open({
       content: data.msg,
       time: 1
      });
      localStorage.setItem("u_id", data.user.id);
      localStorage.setItem("token", data.token);


      // 获取系统数据
      var data1 = {
       uid: data.user.id,
       token: data.token,
       language_type: language_type,
      }
      $.ajax({
       type: 'post',
       url: baseURL + '/index.php?m=user&c=config_setup',
       data: data1,
       success: function success(data) {
        data = JSON.parse(data);
        is_login(data);
        if (data.code == 1) {
         console.log(data.config.w_name)
         localStorage.setItem("isRenzheng", data.is_check) // 是否实名认证 0-没有 1-有 2-待审核
         localStorage.setItem("isBank", data.is_pay) // 是否添加银行卡 0-没有 1-有
         localStorage.setItem("document_name", data.config.w_name);
         setTimeout(function () {
          window.location.href = 'index.html'
         }, 1000);
        }
       }
      })
     } else {
      layer.open({
       content: data.msg,
       time: 1
      });
     }
    }
   });
  }
  
 })
})
